<template>
	<el-dialog  title="" width="80%" size='tiny'  :visible.sync="dialogTableVisible" class="wrap"  :append-to-body="true">
		<el-dialog title="物品导出" width="30%" :visible.sync="dialogTableVisible1" class="wrap" @close="cancel1" :append-to-body="true" >
			<div style="font-size: 20px; text-align: center;">
				<a :href="arr" style="width: 100%;">下载数据</a>
			</div>
		</el-dialog>
        <i class="el-icon-close close" @click="cancel" style="color: white;z-index:10;"></i>
        <div class="bt">新增入库物品清单</div>
        <div class="student1">
        	<el-button type="danger"  class="but1" size="small" @click="cancel" >退出</el-button>
         <el-button type="primary" class="but1" size="small" @click="componentsShow('xzwp')">选择物品</el-button>
         <el-button type="success" class="but1" size="small" @click="sumbit" v-if="this.dataList.length>0">确定入库</el-button>
         <el-button type="info"    class="but1" size="small" @click="daochu" v-if="this.dataList.length>0">物品导出</el-button>
         
         <el-upload
		  class="but1"
		  :action="wjurl"
		  :on-success = "successlist"
		  :on-preview="handlePreview"
		  :file-list="fileList"
		  :show-file-list="false"
		  style="margin-left: 10px;"
		  >
         <el-button type="warning"  size="small" >导入入库单</el-button>
        </el-upload>
        </div>
        <!-- 数据表格展示区域 -->
        <el-table
            :data="dataList"
            border
            stripe
            align="center"
            class="admin-table"
            sum-text
            :row-class-name="tableRowClassName"
            @select="checkSelect"
            @select-all="checkall">
            <div slot='empty'>
                <img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
                <span style="vertical-align: middle;">暂时还没有内容哦!</span>
            </div>
            <el-table-column
                :prop="v.prop"
                :label="v.label"
                v-for="(v,index) in portTitleList"
                align="center"
                show-overflow-tooltip
                v-if="v.hide != 0"
                :formatter="v.formatter"
                :align="v.align || 'center'"
                :fixed="v.fixed"
                :class-name="v.columnStyle"
                :width="v.width"
                :min-width="v.minWidth"
                :header-align="v.headerAlign || 'center'"
                >
                <template scope="scope">
                    <div slot="reference" :style="tableCellControl(scope)" v-if="scope.column.property === 'number' ||  scope.column.property === 'jg'">
                        <el-input class="content-input" type="number" v-model="scope.row[scope.column.property]" ></el-input>
                        <!-- :disabled="scope.row.type === '物品' && scope.column.property === 'zk' ? true:false" -->
                    </div>
                    <div slot="reference" v-else-if="scope.column.property === 'yj'">
                        {{scope.row.jg * scope.row.number }}
                    </div>
                    <div slot="reference" v-else>
                       {{ scope.row[scope.column.property] }}
                    </div>
                 </template>
            </el-table-column>
            <el-table-column
                label="操作"
                align="center"
                width="100px"
                fixed="right">
                <template scope="scope">
                    <el-button size="small" type="danger" @click="yichu(scope)" >移除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <!--<el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="pageindex"
            :page-sizes="pagesizes"
            :page-size="pagesize"
            :layout="layout"
            :total="total"
            class="class-page">
        </el-pagination>-->
        <!-- 各个组件显示区域 -->
        <!-- 动画加载 -->
        <LoadingComponent v-show="isLoading"></LoadingComponent>
        <!-- 选择学生组件 -->
        <!--<StudentComponent v-if="portComponents.student.toggle"  @close="componentsHide"  :data="portComponents.student.data"></StudentComponent>-->
        <!-- 购买课时 -->
        <!--<PayCourse v-if="portComponents.course.toggle"  @close="componentsHide"  :data="portComponents.course.data"></PayCourse>-->
        <!-- 购买物品 -->
		<Xzwplist v-if="portComponents.xzwp.toggle"  @close="componentsHide"  :data="portComponents.xzwp.data" :params="this.wpfl"></Xzwplist>
        <!-- 单独删除组件 -->
        <DeleteComponent v-if="portComponents.singleDelete.toggle"  @close="componentsHide" :params="portComponents.singleDelete.params" :data="portComponents.singleDelete.data"></DeleteComponent>
        <!-- 子路由显示区域 -->
        <router-view class="port-view"></router-view>
</el-dialog>
</template>

<script>
    import Vue from 'vue'
    import { mapState } from 'vuex'
    import LoadingComponent from 'components/loading'
    import DeleteComponent from './del'
//  import StudentComponent from './student'
//  import PayCourse from './pay-course'
    import Xzwplist from '../bs/xzwp'
    import qs from 'qs'
    export default {
    	props: ['params'],
        components: {
            LoadingComponent,
            DeleteComponent,
//          StudentComponent,
//          PayCourse,
            Xzwplist
        },
        data () {
            return {
            	arr:'',
            	wjurl:this.$store.state.api + 'user/saveimg',
            	fileList:[],
            	dialogTableVisible: true,
            	dialogTableVisible1: false,
            	wpfl:this.$route.query.frompagewpfl,
            	vkeyword:'',
                student: '',
                studentList: [],
                date: '',
                ticket: 0,
                studentid:"",
                orderid: '',
                mblist:[],
                mblist2:[],
                yuer:'',
                zfyuer:'',
                lx:'',
                dialogAccounts: false,
                // goodsTotal: 0.00,
                // courseTotal: 0.00,
                money: {
                    xj: '',
                    zfbzh: '',
                    zfbzhje: '',
                    wxzh: '',
                    wxzhje: '',
                    yhzh: '',
                    yhzhje: ''
                },
                /*组件区域*/
                portComponents: {
                    singleDelete: {
                        type: 'singleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'single',
                            title: '此操作将删除该物品, 是否继续?'
                        }
                    },
                    multipleDelete: {
                        type: 'multipleDelete',
                        toggle: false,
                        params: '',
                        data: {
                            index: '',
                            type: 'multiple',
                            title: '此操作将删除您选中的班级, 是否继续?'
                        }
                    },
//                  student : {
//                      type: 'student',
//                      toggle: false,
//                      params: '',
//                      data: {}
//                  },
//                  course : {
//                      type: 'course',
//                      toggle: false,
//                      params: '',
//                      data: {}
//                  },
                    add : {
                        type: 'add',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    xzwp : {
						type: 'xzwp',
						toggle: false,
						params: '',
						data: {}
					}
                },

                multipleDelNum:'', //获取批量选择的数据
                dataList: [],  //表格数据
                /*
                    prop :  接口参数名
                    label : 接口中文名
                    hide : 是否隐藏这一列
                    align : 这一列对齐顺序 ： left,right,center
                    headerAlign : 这一列表头对齐方式 ： left,right,center
                    formatter: function (row, column) {}
                */
                portTitleList: [
                    {
                        prop:'wpflmc',
                        label:'物品分类',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'mc',
                        label:'物品名称',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'jg1',
                        label:'单价/单位',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'jg',
                        label:'入库单价',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'number',
                        label:'物品数量',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'yj',
                        label:'物品总价',
                        hide:1,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    },
                    {
                        prop:'dw',
                        label:'单位',
                        hide:0,
                        align:'center',
                        fixed:false,
                        width:'',
                        minWidth:'100',
                        headerAlign:'center'
                    }
                ],
                portBntList: [//接口按钮列表
                    {
                        name:'删除',
                        type:'singleDelete'
                    }
                ],

                /*动画加载*/
                isLoading: true,//动画加载
                searchLoading: false,//搜索按钮触发按钮动画

                /*模糊搜索条件*/
                inputbjmc:'' , //  班级名称,


                /*分页属性设置*/
                layout: 'total, sizes, prev, pager, next, jumper',//组件布局
                pageindex: 1,//当前分页页码
                pagesizes: [12, 24, 36, 72],//显示个数的选择器选项
                pagesize: 12,//每页显示条目数
                total: 0,//总条数


                dropDownData:'', //
            }
        },
        created () {
             this.wpfl =this.params;
             var vpage =this.params;
            //加载页面时调用
            if( vpage== '12'){
               this.$store.dispatch('changeTitle','教材、学习用品类新增入库');//修改title
            }else if(vpage == '3'){
                     this.$store.dispatch('changeTitle','固定资产类新增入库');//修改title
            }else if(vpage== '4'){
                     this.$store.dispatch('changeTitle','易耗品类新增入库');//修改title
            }else{
                  this.$store.dispatch('changeTitle','新增入库');//修改title
            }
            this.$store.dispatch('changeRouterIndex','/manage/jh');//修改路由

            this.isLoading = true;//动画开始
        },
        mounted () {
            this.isLoading = false;//动画结束
        },
        watch:{
            'zfyuer': function(newVal,oldVal){
                if(parseInt(newVal)>=parseInt(this.yuer)) {//如果小于等于零
                    this.zfyuer = this.yuer //恢复原值
                }
            }
        },
        methods: {
        	yichu(id){
        		this.dataList.splice(id.$index,1)
        	},
        	 successlist(res, file, fileList){
        	 	console.log(res,'9999999999999999')
		      	var path= res
		      	this.lj(path)
		      },
		      handlePreview(file) {
		      },
		  lj(path){
        	 var logininfo = JSON.parse(localStorage.logininfo);
             var params2 = qs.stringify({
             	     path:path
               })
             //执行
                 this.axios.post(this.$store.state.api + 'readexcewp',  params2 )
                 .then(res => {
                 	var list = res.data.data
                 	var list2=[]
                 	for(var i in list){
                 		list2.push(list[i][0])
                 	}
                 	this.dataList = list2
                 }).catch(res => {
				})
        	},
	      daochu(){
	      	var wplist = ""
	      	for(var i in this.dataList){
	      		wplist += this.dataList[i].id+","+this.dataList[i].mc+","+this.dataList[i].wpflid+","+this.dataList[i].wpflmc+";"
	      	}
	      	 var logininfo = JSON.parse(localStorage.logininfo) ;
                       var params3 = qs.stringify({
                     			list:wplist,
                     			xxid:logininfo.xxid,
            			});
                        this.axios.post(this.$store.state.api + 'inputexcelaaaaa', params3)
                        .then( res => {
//                      	console.log(res,989898888888)
                        	this.dialogTableVisible1 = true
                        	this.arr = res.data
//                      	window.open(res.data);
                        }).catch( res => {
                        	this.$message.warning("服务器繁忙，请重试");
                        	this.$store.state.loading = false;
                        })
	      },
          sumbit(){
                    this.dataList.forEach( (v, i) => {
						           var add = v.number *v.jg
                    	 var logininfo = JSON.parse(localStorage.logininfo) ;
                       var params3 = qs.stringify({
                           yhid: logininfo.id,
                           xxid: logininfo.xxid,
                           wpid:v.id+'',
                           wpflid:v.wpflid+'',
                           sl:v.number+'',
                           dj:v.jg+'',
                           zj:add+'',
                           dw:v.dw+''
            						});
                        this.axios.post(this.$store.state.api + 'wprkdmx/insert', params3)
                        .then( res => {
                            if(res.data.code == 0) {
							this.$emit('close', { type: 'jhlist', cancel: false });
							this.$message.success(res.data.msg);
							this.$store.state.loading = false;
						} else {
						    this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
                        }).catch( res => {
                        	this.$message.danger("服务器繁忙，请重试");
                        	this.$store.state.loading = false;
                        })
                })
          },
          cancel() {
 				this.$emit('close', { type: 'jhlist', cancel: true })
 			},
 			cancel1() {
 				this.dialogTableVisible1 = false
 			},
            tableRowClassName (row, index) {//隔行变色颜色设置
                /*if ( index%4 == 0) {
                    return "table-cell-green";
                }else if( index%4 == 1 ){
                    return "table-cell-yellow";
                }else if( index%4 == 2 ){
                    return "table-cell-red";
                }else{
                    return "table-cell-blue"
                }*/
            },
            tableCellControl (scope) {//表格单元格控制CSS样式
                // console.log(scope)
                /*if (scope.row.id == 112 && scope.column.property == "iname") {
                    return {
                        color:"red",
                    }
                }else{
                    return {
                        color:"green",
                    }
                }*/
            },
             handleSizeChange (val) {//每页显示条数触发事件
                this.pagesize = val;
                this.pageindex = 1;
                this.search();
            },
            handleCurrentChange (val) {//分页触发事件
                this.search();
            },
            checkSelect (selection, row) {//点击单选select触发事件
                let strID = [];
                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            checkall (selection) {//点击全选select触发事件
                // console.log(selection)
                let strID = [];

                selection.forEach(function(v,i){
                    strID.push(v.id)
                })
                this.multipleDelNum = strID.join(",");
            },
            /* 组件的弹框  */
            componentsShow (type,data) { //显示组件
                for ( let i in this.portComponents ) {
                    if (type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = true;
                        this.portComponents[i].params = data;
                        if (this.portComponents[i].data.type == 'single') {
                            this.portComponents[i].data.index = data.row.id
                        }else if(this.portComponents[i].data.type == 'multiple'){
                            this.portComponents[i].data.index = this.multipleDelNum;
                        }else{
                            return;
                        }
                        return;
                    }
                }
            },
            componentsHide (setting) { //关闭组件
                for ( let i in this.portComponents ) {
                    if (setting.type == this.portComponents[i].type) {
                        this.portComponents[i].toggle = false;
                        if (this.portComponents[i].type == 'singleDelete') {
                            this.dataList.splice(setting.index,1)
                        }
                        if (!setting.cancel) {
                           // this.search();
                            if (setting.type == "student") {
                                this.student = setting.data.zwm + ' - ' + setting.data.xh
                                this.studentid = setting.data.id
                            }else{
                                setting.data.forEach( (v) => {
                             var iscan =true;
                             for ( let z in this.dataList ) {
                             	if(this.dataList[z].id==v.id){
                             		iscan =false;
                             		break;
                             	}
                             }
							if (iscan){
                               this.dataList.push(v);
                              }
                            })
                            }
                        }
                        return;
                    }
                }
            }
        },
        computed: {
        }
    }
</script>

<style lang="less" scoped>
.mb{
  margin-left: 50px;
}

 .student1 {
        	width: 100%;
        	height:50px;
			overflow: hidden;
			.but1{
				float: left;
			}
        }
.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
    .index-page {
        font-size:12px;
        position: relative;

       


        .state {
            width:100%;
            margin-top:20px;
            text-align: center;

            .left,.right {
                float: left;
                width: 50%;
            }

            h3 {
                // width: 350px;
                text-align: center;
                color:#333;
            }
            .item {
                width: 350px;
                margin:10px 0;
            }

            .amount {
                font-size:30px;
                margin-top:20px;
            }

            .left span{
                display: inline-block;
                width:100px;
                text-align: right;
                coloe:#737373;
            }
            .right {
                text-align: left;
            }

            .right .item {
                width:500px;

                .title {
                    width: 300px;
                }

                .content {
                    width:150px;
                }
            }
            .right .xj {
                width:400px;
            }
        }

        .content-input {
            height:20px;
        }

        .submit {
            width:120px;
            display: block;
            margin:20px auto;
        }
        .input {
        	min-width: 120px;
        	max-width: 150px;
        }

        .item-input {
            width: 200px;
        }

        .total {
            text-align: right;
            margin:10px 0;
            span{
                margin:0 10px;
            }
        }

        .dailog .el-dialog {
            width: 70%;
        }
        article {
            margin:40px 0;
            margin-top:20px;

            p{
                background: #fcf4eb;
                padding:10px 5px;
            }
            input {
                border:none;
                outline: none;
                background: transparent;
                border-bottom:1px solid #ccc;
            }
            div {
                background: rgba(252,244,235,0.7);
                padding:10px 5px;
            }
            .space-between {
                padding:10px 0;
                display: block;
            }
        }

        .settlement {
            p{
                background: #fcf4eb;
            }
            div {
                background: rgba(252,244,235,0.7);
            }
        }

        .receiving-account {
            p{
                background: #F1FDFC;
            }
            div {
                background: rgba(241,253,252,0.7);
            }
        }

        .other-information {
            p{
                background: #e5e9f2;
            }
            div {
                background: rgba(229,233,242,0.7);
            }
        }
    }
</style>
